<?php

namespace addons\Contract\common\models;

use Yii;

/**
 * This is the model class for table "{{%addon_oa_contract}}".
 *
 * @property int $id
 * @property string $title 标题
 * @property string $serial 合同编号
 * @property string $content 内容
 * @property string $PartyA 甲方
 * @property string $PartyB 乙方
 * @property string $date 签定时间
 * @property int $status 状态
 * @property int $created_at 创建时间
 * @property int $updated_at 修改时间
 */
class Contract extends \common\models\base\BaseModel
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return '{{%addon_contract}}';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['cate_id','title', 'PartyA', 'PartyB', 'date'], 'required'],
            [['date','covers'], 'safe'],
            [['merchant_id', 'status', 'created_at', 'updated_at'], 'integer'],
            [['title', 'PartyA', 'PartyB'], 'string', 'max' => 255],
            [['serial'], 'string', 'max' => 32],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'cate_id' => '合同类型',
            'title' => '合同名称',
            'serial' => '合同编号',
            'covers' => '合同图片',
            'PartyA' => '甲方',
            'PartyB' => '乙方',
            'date' => '签定时间',
            'status' => '状态',
            'created_at' => '创建时间',
            'updated_at' => '修改时间',
        ];
    }

    public function beforeSave($insert)
    {
        $this->merchant_id = Yii::$app->user->identity->merchant_id;

        return parent::beforeSave($insert);
    }

}